<template>
  <div id="loading" v-show="visible">
    <div class="loader">
      <div class="loader-inner pacman">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
      </div>
    </div>
  </div>
</template>

<script>
import { defineComponent, ref } from "vue";
export default defineComponent({
  name: "Loading",
  setup() {
    // 控制组件的状态
    let visible = ref(false);

    // 显示组件
    let showLoading = () => {
      visible.value = true;
    };
    // 隐藏组件
    let hideLoading = () => {
      visible.value = false;
    };

    return { visible, showLoading, hideLoading };
  },
});
</script>
<style scoped>
#loading {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
body {
  padding: 1.25rem;
}

.loader {
  min-height: 1.25rem;
}

@-webkit-keyframes rotate_pacman_half_up {
  0% {
    -webkit-transform: rotate(270deg);
    transform: rotate(270deg);
  }

  50% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }

  100% {
    -webkit-transform: rotate(270deg);
    transform: rotate(270deg);
  }
}

@keyframes rotate_pacman_half_up {
  0% {
    -webkit-transform: rotate(270deg);
    transform: rotate(270deg);
  }

  50% {
    -webkit-transform: rotate(360deg);
    transform: rotate(360deg);
  }

  100% {
    -webkit-transform: rotate(270deg);
    transform: rotate(270deg);
  }
}

@-webkit-keyframes rotate_pacman_half_down {
  0% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
  }

  50% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  100% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
  }
}

@keyframes rotate_pacman_half_down {
  0% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
  }

  50% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  100% {
    -webkit-transform: rotate(90deg);
    transform: rotate(90deg);
  }
}

@-webkit-keyframes pacman-balls {
  75% {
    opacity: 0.7;
  }

  100% {
    -webkit-transform: translate(-1.25rem, -0.0781rem);
    transform: translate(-1.25rem, -0.0781rem);
  }
}

@keyframes pacman-balls {
  75% {
    opacity: 0.7;
  }

  100% {
    -webkit-transform: translate(-1.25rem, -0.0781rem);
    transform: translate(-1.25rem, -0.0781rem);
  }
}

.pacman {
  position: relative;
}

.pacman > div:nth-child(2) {
  -webkit-animation: pacman-balls 1s 0s infinite linear;
  animation: pacman-balls 1s 0s infinite linear;
}

.pacman > div:nth-child(3) {
  -webkit-animation: pacman-balls 1s 0.33s infinite linear;
  animation: pacman-balls 1s 0.33s infinite linear;
}

.pacman > div:nth-child(4) {
  -webkit-animation: pacman-balls 1s 0.66s infinite linear;
  animation: pacman-balls 1s 0.66s infinite linear;
}

.pacman > div:nth-child(5) {
  -webkit-animation: pacman-balls 1s 0.99s infinite linear;
  animation: pacman-balls 1s 0.99s infinite linear;
}

.pacman > div:first-of-type {
  width: 0px;
  height: 0px;
  border-right: .3125rem solid transparent;
  border-top: .3125rem solid #409eff;
  border-left: .3125rem solid #409eff;
  border-bottom: .3125rem solid #409eff;
  border-radius: .3125rem;
  -webkit-animation: rotate_pacman_half_up 0.75s 0s infinite;
  animation: rotate_pacman_half_up 0.75s 0s infinite;
}

.pacman > div:nth-child(2) {
  width: 0px;
  height: 0px;
  border-right: .3125rem solid transparent;
  border-top: .3125rem solid #409eff;
  border-left: .3125rem solid #409eff;
  border-bottom: .3125rem solid #409eff;
  border-radius: .3125rem;
  -webkit-animation: rotate_pacman_half_down 0.75s 0s infinite;
  animation: rotate_pacman_half_down 0.75s 0s infinite;
  margin-top: -0.625rem;
}

.pacman > div:nth-child(3),
.pacman > div:nth-child(4),
.pacman > div:nth-child(5) {
  background-color: #409eff;
  width: .1875rem;
  height: .1875rem;
  border-radius: 100%;
  margin: .025rem;
  width: .125rem;
  height: .125rem;
  position: absolute;
  -webkit-transform: translate(0, -0.0781rem);
  -ms-transform: translate(0, -0.0781rem);
  transform: translate(0, -0.0781rem);
  top: .3125rem;
  left: 1.25rem;
}
</style>
